/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.wido.ui;


import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;
import cs575.wido.action.GroupTaskAction;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
 *
 * @author kevincheung
 */
public class GroupDetailsPane extends JPanel {
	private GroupDetailsWindow parent;
	
	private JButton btnCancel;
	private JButton btnOk;
	
	private JTextField txtName;
	private JTextArea txtDescription;
	
	public GroupDetailsPane(GroupDetailsWindow parent) {
		this.parent = parent;
		this.setLayout(new BorderLayout(0, 0));
		
		JComponent formPanel = buildFormPanel();
		JComponent buttonPane = buildButtonPane();
		
		this.add(formPanel, BorderLayout.CENTER);
		this.add(buttonPane, BorderLayout.SOUTH);
	}
	
	private JComponent buildFormPanel() {
		JLabel lblName;
		JLabel lblDescription;
		
		JPanel formPanel = new JPanel();
		formPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		formPanel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.MIN_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		lblName = new JLabel("Name");
		formPanel.add(lblName, "2, 2, right, default");
		
		txtName = new JTextField();
		formPanel.add(txtName, "4, 2, fill, default");
		txtName.setColumns(10);
		
		lblDescription = new JLabel("Description");
		formPanel.add(lblDescription, "2, 4");
		
		txtDescription = new JTextArea();
		
		JScrollPane scrollPane = new JScrollPane(txtDescription);
		formPanel.add(scrollPane, "4, 4, fill, fill");
		
		return formPanel;
	}
	
	private JComponent buildButtonPane() {
		JPanel buttonPane = new JPanel();
		FlowLayout flowLayout = (FlowLayout) buttonPane.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		
		JButton btnGroupTasks = new JButton("Group Tasks");
		btnGroupTasks.setAction(new GroupTaskAction(parent.getGroup()));
		buttonPane.add(btnGroupTasks);
		
		btnOk = new JButton("OK");
		buttonPane.add(btnOk);
		
		btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				GroupDetailsPane.this.parent.dispose();
			}
		});
		buttonPane.add(btnCancel);
		
		return buttonPane;
	}
	
	public void setGroup(cs575.client.GroupEx group) {
		String name = group.getGroupName();
		String description = group.getGroupDescription();
		txtName.setText(name);
		txtDescription.setText(description);
	}
        
        public void setGroup(String[] group) {
            txtName.setText(group[0]);
            txtDescription.setText(group[1]);
        }
}
